//
//  NYMessageViewController.m
//  Nooryes
//
//  Created by baken on 2020/3/1.
//  Copyright © 2020 MyApp. All rights reserved.
//

#import "NYMessageViewController.h"
#import "NYMessageTableViewCell.h"
#import "NYAcccountViewModel.h"
#import "NYMessageListModel.h"

@interface NYMessageViewController ()

@property (weak, nonatomic) IBOutlet UITableView *tableview;

@property (nonatomic, strong) NYAcccountViewModel *accountVM;
@end

@implementation NYMessageViewController


-(NYAcccountViewModel *)accountVM{
    if (!_accountVM) {
        _accountVM = [NYAcccountViewModel new];
    }
    return _accountVM;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"我的消息";
    self.tableview.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
    [self.accountVM getMessageListWithCompletionHandle:^(NSError *error) {
        if (!error) {
            [self.tableview reloadData];
        }
    }];
    
}

#pragma mark UITableView
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MessageListModel *model = [self.accountVM.msgArray objectAtIndex:indexPath.row];
    NYMessageTableViewCell *cell = [NYMessageTableViewCell cellWithTableView:tableView];
    cell.model = model;
    return cell;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.accountVM.msgArray.count;
}
@end
